package com.mygdx.game.part3;

import java.util.Random;

/**
 * RandomUtils
 * Created by 80002023 on 2016/8/15.
 */
public class RandomUtils {

    public static EnemyType getRandomEnemyType() {
        RandomEnum<EnemyType> randomEnum = new RandomEnum<EnemyType>(EnemyType.class);
        return randomEnum.random();
    }

    /**
     * @see [Stack Overflow](http://stackoverflow.com/a/1973018)
     * @param <E>
     */

    private static class RandomEnum<E extends Enum> {
        private static final Random RANDOM = new Random();
        private final E[] values;

        public RandomEnum(Class<E> values) {
            this.values = values.getEnumConstants();
        }

        public E random() {
            return values[RANDOM.nextInt(values.length)];
        }
    }
}
